package bd.proiect;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.SeekBar;

public class AddSpecies extends Activity{
	
	private String name;
	private int ease;
	private boolean flowering;
	private boolean foliage;
	private String description;
	
	EditText ed_name;
	EditText ed_description;
	SeekBar sb;
	CheckBox cb_flower;
	CheckBox cb_foliage;
	
	DataBase bs;
	
	@Override
	  public void onCreate(Bundle savedInstanceState) {
	     super.onCreate(savedInstanceState);
	     setContentView(R.layout.addspecies);
	     
	     ed_name = new EditText(this);
         ed_name = (EditText)findViewById(R.id.addspecies_name);
         
         ed_description = new EditText(this);
         ed_description = (EditText)findViewById(R.id.addspecies_description);
         
         sb = new SeekBar(this);
         sb.setMax(10);
         sb = (SeekBar)findViewById(R.id.SeekBar01);
         
         cb_flower = new CheckBox(this);
         cb_flower = (CheckBox)findViewById(R.id.flowering);
         
         cb_foliage = new CheckBox(this);
         cb_foliage = (CheckBox)findViewById(R.id.foliage);
         
         bs = new DataBase(this);
         
         Button SaveButton = (Button) findViewById(R.id.addgenus_button);
	     SaveButton.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	name = ed_name.getText().toString();
	        	ease = sb.getProgress();
	        	flowering = cb_flower.isChecked();
	        	foliage = cb_foliage.isChecked();
	        	description = ed_description.getText().toString();
	    	   
	    	    try{
	    				bs.createDataBase();
	    				bs.openDataBase();
	    				bs.insertSpecies(name, 1 ,ease, flowering, foliage,description);
	    				bs.close();
	    				finish();
	    				
	    		}catch(Exception e){
	    			ed_name.setText("buba" + e);
	    		}
	    		//finish();
	         }
	     });
	     
	     }

}
